%option noyywrap
%{
#include <stdio.h>
#include <stdlib.h>

int line_number = 0; // 行号初始化
int column_number = 0; // 列号初始化
%}

%%
"void"     { printf("Token: 259\tText: void\tLine: %d\t(s,e): (%d,%d)\n", line_number, column_number, column_number + yyleng); column_number += yyleng; }
"main"     { printf("Token: 263\tText: main\tLine: %d\t(s,e): (%d,%d)\n", line_number, column_number, column_number + yyleng); column_number += yyleng; }
"("        { printf("Token: 269\tText: (\tLine: %d\t(s,e): (%d,%d)\n", line_number, column_number, column_number + yyleng); column_number += yyleng; }
")"        { printf("Token: 270\tText: )\tLine: %d\t(s,e): (%d,%d)\n", line_number, column_number, column_number + yyleng); column_number += yyleng; }
"{"        { printf("Token: 273\tText: {\tLine: %d\t(s,e): (%d,%d)\n", line_number, column_number, column_number + yyleng); column_number += yyleng; }
"}"        { printf("Token: 274\tText: }\tLine: %d\t(s,e): (%d,%d)\n", line_number, column_number, column_number + yyleng); column_number += yyleng; }
"return"   { printf("Token: 262\tText: return\tLine: %d\t(s,e): (%d,%d)\n", line_number, column_number, column_number + yyleng); column_number += yyleng; }
"int"      { printf("Token: 258\tText: int\tLine: %d\t(s,e): (%d,%d)\n", line_number, column_number, column_number + yyleng); column_number += yyleng; }
[0-9]+     { printf("Token: 275\tText: %s\tLine: %d\t(s,e): (%d,%d)\n", yytext, line_number, column_number, column_number + yyleng); column_number += yyleng; }
";"        { printf("Token: 287\tText: ;\tLine: %d\t(s,e): (%d,%d)\n", line_number, column_number, column_number + yyleng); column_number += yyleng; }
[a-zA-Z_][a-zA-Z0-9_]* {
    printf("Token: 263\tText: %s\tLine: %d\t(s,e): (%d,%d)\n", yytext, line_number, column_number, column_number + yyleng - 1);
    column_number += yyleng;
}
[\n]       { line_number++; column_number = 0; }
[ \t]      { column_number += yyleng; }
.          { printf("Unknown character: %s at line %d, column %d\n", yytext, line_number, column_number); column_number += yyleng; }
%%

int main() {
    yylex();
    return 0;
}